package com.cloudptt.wp.ui.message;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.target.Target;
import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ScreenManager;

import java.io.File;

public class ImageActivity extends Activity implements View.OnClickListener {
    private ImageView imageView;
    private String localPath = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_image);
        LinearLayout mainLy =(LinearLayout)findViewById(R.id.mainLy);
        mainLy.setOnClickListener(this);

        imageView = findViewById(R.id.imageView);
        mainLy.setOnClickListener(this);
        localPath = getIntent().getStringExtra("local_path");

        ScreenManager.getScreenManager().pushActivity( this );
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.debug(getClass(), "onResume localPath = " + localPath);

//        Picasso.get().load("file://" + localPath).fit().centerInside().into(imageView);
//        Picasso.get()
//                .load("file://" + localPath)
//                .memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE)
//                .networkPolicy(NetworkPolicy.NO_CACHE)
//                .into(imageView);
        File file = new File(localPath);
        Glide.with(ImageActivity.this)
                .load(file)
                .override(Target.SIZE_ORIGINAL, 1024)
                .placeholder(R.drawable.placeholder)  // 加载中占位图
                .error(R.drawable.error_image)
                .into(imageView);

    }

    @Override
    public void onClick(View view) {
        if(view.getId()==R.id.mainLy
            || view.getId()==R.id.imageView) {
            ScreenManager.getScreenManager().popActivity();
//            this.finish();
        }
    }
}

